﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NHModel.Entities;
using NHBLL;

namespace StudyAdmin.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {           
            if (Session["TeacherID"] == null)
            {
                Session["TeacherID"] = "1";
                return View();
                //return RedirectToAction("Login", "Home"); 
            }
            return View();
        }

        public ActionResult LogOut()
        {
            Session["TeacherID"] = null;
            return RedirectToAction("Login");
        }

        public ActionResult About()
        {
            return View();
        }
        public ActionResult Login()
        {
            return View();
        }
        
        [HttpPost]
        public ActionResult Login(string UserName,string PassWord)
        {
            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(PassWord))
            {
                ViewData["Msg"] = "用户名或密码不能为空";
                return View();
            }

            //用户验证
            TeacherInfo item = TeacherInfoService.GetModelByUserNameAndPass(UserName, PassWord);
            if (item != null)
            {
                Session["TeacherID"] = item.Id;
                return RedirectToAction("Index", "Home"); 
            }
            ViewData["Msg"] = "用户名或密码不正确";
            return View();         
        }
    }
}
